import store from '@/store'

export default {
  inserted(el, binding) {
    const buttons = store.getters.buttons || []
    console.log('权限检查:', binding.value, '当前按钮列表:', store.getters.buttons)
    if (!buttons.includes(binding.value)) {
      el.parentNode && el.parentNode.removeChild(el)
    }
    const { value } = binding
    const role = store.getters.role

    if (value) {
      // 如果是管理员，拥有所有权限
      if (role === '管理员') {
        return true
      }
      
      // 如果是讲师，检查权限
      if (role === '讲师') {
        // 这里可以根据实际需求定义讲师的权限列表
        const teacherPermissions = [
          'course:add',
          'course:edit',
          'course:delete',
          'note:add',
          'note:edit',
          'note:delete'
        ]
        
        if (!teacherPermissions.includes(value)) {
          el.parentNode && el.parentNode.removeChild(el)
        }
      }
    } else {
      throw new Error('需要指定权限标识')
    }
  }
} 